package com.itbaizhan.shopping_manager_api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itbaizhan.shopping_common.pojo.Category;
import com.itbaizhan.shopping_common.result.BaseResult;
import com.itbaizhan.shopping_common.service.CategoryService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @DubboReference
    private CategoryService categoryService;
    /**
     *  添加广告
     */
    @PostMapping("/add")
    public BaseResult add(@RequestBody  Category category){
        categoryService.add(category);
        return BaseResult.ok();
    }

    /**
     * 修改广告
     */
    @PutMapping("/update")
    public BaseResult update(@RequestBody Category category){
        categoryService.update(category);
        return BaseResult.ok();
    }


    /**
     * 批量删除广告
     */
    @DeleteMapping("/delete")
    public BaseResult delete(Long[] ids){
        categoryService.delete(ids);
        return BaseResult.ok();
    }

    /**
     * 修改广告状态
     */
    @PutMapping("/updateStatus")
    public BaseResult updateStatus(Long id,Integer status){
        categoryService.updateStatus(id,status);
        return BaseResult.ok();
    }

    /**
     * 根据id查询广告
     */
    @GetMapping("/findById")
    public BaseResult findById(Long id){
        Category category = categoryService.findById(id);
        return BaseResult.ok(category);
    }

    /**
     * 分页查询所有广告
     */
    @GetMapping("/search")
    public BaseResult<Page<Category>> search(Integer page, Integer size){
        return BaseResult.ok(categoryService.search(page,size));
    }


}
